; main.asm
; vin Main
;
	.include "common.inc"
	.include "screen.inc"
	.include "mouse.inc"
	.include "joymouse.inc"
	.include "keyboard.inc"
	.include "window.inc"
	.include "menubar.inc"
	.include "timer.inc"
	.include "scrsaver.inc"

	.import brkhdl
	
	.export startup

	IRQ_TAIL = $EB15

	.segment	"DATA"

next_irq:	.word $0000
last_sec:	.byte $00
jiffies:	.byte $00, $00, $00

	.segment	"CODE"
	
startup:	; init panic handler
			lda #<brkhdl
			sta BRK_VECTOR
			lda #>brkhdl
			sta BRK_VECTOR+1
			; init timer
			jsr init_timer
			; init screen
			jsr	sg_init
			; init windows
			jsr win_init
			; init mouse
			jsr init_mouse
			; init keyboard
			jsr init_keyboard
			; init screen saver
			jsr init_saver
			; init menu bar
			jsr menu_init
			
			; init mouse handler
			lda #<handle_joymouse
			ldx #>handle_joymouse
			jsr set_mouse_handler
		
			; setup interrupt handler
			lda #<main_irq
			ldx #>main_irq
			sei
			sta IRQ_VECTOR
			stx IRQ_VECTOR+1
			cli
	
			jsr timer_run
	
main_loop:	jsr do_mouse
			jsr do_keyboard
			jsr do_timer
			jsr do_windows
			jmp main_loop

main_irq:	jsr timer_irq
			jsr mouse_irq
			jsr keyb_irq
			jmp IRQ_TAIL

